package com.shanjupay.merchant.controller;

import com.shanjupay.common.domain.BusinessException;
import com.shanjupay.merchant.common.util.SecurityUtil;
import com.shanjupay.merchant.feign.AppFeign;

import com.shanjupay.service.api.dto.AppDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TODO
 *
 * @Description
 * @Author zhangbing
 * @Date 2024/5/20 9:27
 **/
@RestController
public class AppController {

    @Autowired
    private AppFeign appFeign;


    @PostMapping("/createApp")
    public AppDTO createApp(@RequestBody AppDTO app){

        Long merchantId = SecurityUtil.getMerchantId();
        app.setMerchantId(merchantId);
        return  appFeign.createApp(app);
    }

    @GetMapping("/queryApps")
    List<AppDTO> queryAppByMerchantId()throws BusinessException{
        Long merchantId = SecurityUtil.getMerchantId();
        List<AppDTO> appDTOS = appFeign.queryAppByMerchantId(merchantId);
        return appDTOS;
    }

    @GetMapping("/MyApp/{appId}")
    public AppDTO getApp(@PathVariable String appId){
       return appFeign.getAppById(appId);
    }
}
